package com.leetcode.LC;

public class LC125 {
    public boolean isPalindrome(String s) {

        s = s.toLowerCase();
        char[] chars = s.toCharArray();
        int a = 0, b = s.length() - 1;
        while (b > a) {
            if (Character.isLetterOrDigit(chars[a]) && Character.isLetterOrDigit(chars[b])) {
                if (chars[a] != chars[b])
                    return false;
            }
            if (!Character.isLetterOrDigit(chars[a])) {
                a++;
                continue;
            }
            if (!Character.isLetterOrDigit(chars[b])) {
                b--;
                continue;
            }
            a++;
            b--;
        }
        return true;
    }
    public static void main(String[] args) {
        System.out.println(new LC125().isPalindrome("A man, a plan, a canal: Panam"));
    }
}
